﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HomeWork08;
namespace OrderForms
{
    public partial class Form2 : Form
    {
        private OrderService orderService;
        private string orderNum;
        private string client;
        private string address;
        private string name;    //商品名称
        private double price;    //商品单价
        private int number;     //需求量

        public int Number { get => number; set => number = value; }
        public double Price { get => price; set => price = value; }
        public string MyName { get => name; set => name = value; }


        public string OrderNum
        {
            get => orderNum;
            set => orderNum = value;
        }
        public string Client
        {
            get => client;
            set => client = value;
        }
        public string Address
        {
            get => address;
            set => address = value;
        }

        public Form2()
        {
            InitializeComponent();
            orderService = new OrderService();
        }
        public Form2(OrderService orderService,string orderNum) : this()
        {
            this.orderService = orderService;
            this.orderNum = orderNum;
        }

        private void btnEnsure_Click(object sender, EventArgs e)
        {
            if (this.Text.Equals("创建订单"))
                orderService.CreatOrder(orderNum, address, client);
            else if (this.Text.Equals("添加订单明细"))
            {
                orderService.addOrder(this.orderNum, name, price, number);
            }
            else if (this.Text.Equals("查询订单")) ;
                
                this.Close();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            if(this.Text.Equals("创建订单"))
            {
                label1.Text = "订单编号：";
                label2.Text = "地址：";
                label3.Text = "客户姓名：";
                orderTextBox.DataBindings.Add("Text", this, "OrderNum");
                addressTextBox.DataBindings.Add("Text", this, "Address");
                clientTextBox.DataBindings.Add("Text", this, "Client");
            }
            else if(this.Text.Equals("添加订单明细"))
            {
                label1.Text = "商品名称：";
                label2.Text = "商品单价：";
                label3.Text = "商品数量：";
                orderTextBox.DataBindings.Add("Text", this, "MyName");
                addressTextBox.DataBindings.Add("Text", this, "Price");
                clientTextBox.DataBindings.Add("Text", this, "Number");
            }
            else if (this.Text.Equals("查询订单"))
            {

            }
        }
    }
}
